#pragma once
#include<cocos2d.h>
#include<stack>
#define Wall 3
#define Visited 2
#define Path 1
#define Space 0
#define Start 4
#define End 5
#define MAP_H 6
#define MAP_W 8

class MyVec2:public cocos2d::Vec2 {
public:
	MyVec2(int xx, int yy) :Vec2(xx, yy) {
		parent = nullptr;
		f = 0, g = 0, h = 0;
	};
	MyVec2(const Vec2 &copy) :Vec2(copy) {
		parent = nullptr;
		f = 0, g = 0, h = 0;
	};
	MyVec2(const MyVec2 &copy) {
		this->x = copy.x;
		this->y = copy.y;
		parent = copy.parent;
		f = copy.f;
		g = copy.g;
		h = copy.h;
	}
	friend bool operator <(const MyVec2 &p1, const MyVec2 &p2)
	{
		return p1.f > p2.f;
	}
	~MyVec2() {
		delete parent;
		parent = nullptr;
	}
public:
	MyVec2 *parent;
	double f, g, h;

};

MyVec2* findPoint(std::list<MyVec2 *>list, int x, int y);
bool clearPoint(std::list<MyVec2 *>&list, MyVec2* target);
MyVec2* getMin(std::list<MyVec2 *>m_list);
std::stack<MyVec2> Astar(MyVec2 start, MyVec2 end, int (&map)[MAP_W][MAP_H]);